/**
 * 特权用户页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：特权用户页面
     创建日期：2015-10-19
     修改记录：
     备注说明：
 */

$(document).ready(function() {
	userList();
});


/**
 * 查询操作日志
 * @returns
 */
var userList = function(){
	
	var usernick=$("#usernick").val();
	var remark=$("#remark").val();
	var privilegORC=$("#privilegORC").val();
	 
	var datas =  {"p":"privilegUserManage","m":"qs","name":usernick,"remark":remark,"privilegORC":privilegORC};
	var columnDefine = {"id":"编号","name":"用户昵称","greenCard":"红包特权","remark":"备注"};
	
	var formatters={
	            "greenCard": function (column, rowData)
	            {
    				if(rowData.greenCard==false){
    					return '<font color="#ec4758">已关闭</font>';
    				}else{
    					return '<font color="#18a689">已开启</font>';
    				}
	            }
	 };
	 var buttons =''; //操作按钮
		buttons+='<p>';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-danger\' onclick="openGreenCard();">开启/关闭特权</button>&nbsp;&nbsp;';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-primary\' onclick="showAddRemarkWin();">修改备注</button>&nbsp;&nbsp;';
		buttons+='</p>';
	   hui.pager('service',datas ,"dataList", columnDefine , formatters , buttons ); //分页查询
	
};

var getTheSureTime=function(emp){
	return emp>9?emp:"0"+emp;
};

/**
 * 开启/关闭特权
 * @returns
 */
var openGreenCard = function(){
	var data = $('#pop_win .data').text();
	var json = eval('('+data+')');
	var id = json.id;
	var greenCard = json.greenCard;
	var flag=greenCard == true?false:true;
	var datas={"p":"privilegUserManage","m":"greenCard","id":id,"flag":flag};
	var json=common.ajaxRequest('service', datas, "POST");
	if( json && json.result == 0 )
	{
		userList();
		$('#pop_win').modal('hide');
		common.showMsg('info', '' , '设置为'+(greenCard == true?'关闭':'开启')+'状态' );
	}	
	else
	{
		common.showMsg('info', '' , '设置失败' );
	}	
};

/**
 * 打开添加备注窗口
 * @returns
 */
var showAddRemarkWin = function(){
	
	var data = $('#pop_win .data').text();
	var json = eval('('+data+')');
	var id = json.id;
	$('#addRemarkWin .id').val(id);
	$('#pop_win').modal('hide');
	$('#addRemarkWin').modal('show');
	
};

/**
 * 添加备注
 * @returns
 */
var addRemark = function(){
	var id = $('#addRemarkWin .id').val();
	var remark = $('#addRemarkWin .remark').val();
	var datas = {"p":"privilegUserManage","m":"saveRemark","id":id,"remark":remark};
	var json=common.ajaxRequest('service', datas, "POST");
	if( json && json.result == 0 )
	{
		userList();
		$('#addRemarkWin').modal('hide');
		common.showMsg('info', '' , '添加成功' );
	}	
	else
	{
		common.showMsg('info', '' , '添加失败' );
	}	
	
};


